/**
 * Created with CLion.
 * Description:
 * User: loong
 * Date: 2020-12-13
 * Time: 13:59
 */
#ifndef AUTOUPDATE_FTPMANAGER_H
#define AUTOUPDATE_FTPMANAGER_H

#include <QWidget>
#include <QUrl>
#include <QNetworkReply>
#include <QTextCodec>
#include "IProtocal.h"

class FtpManager
        : public QObject
          , public IProtocal
{
Q_OBJECT

public:
    //explicit FtpManager(QString _path);
    FtpManager() = default;

    ~FtpManager() override = default;

public:
    QNetworkReply *Send(const QString &_local_path, const QString &_upload_path) override;

    QNetworkReply *Receive(const QString &_download_path) override;

public:
    inline void SetUrl(QString _url)
    { url_ = QUrl(_url); };

    inline void SetUrl(QUrl _url)
    { url_ = _url; };

    inline void SetPort(int _port)
    { url_.setPort(_port); }

    inline void SetHost(const QString &_host)
    { url_.setHost(_host); }

    inline void SetPath(const QString &_path)
    { url_.setPath(_path); }

    inline void SetUserName(const QString &_userName)
    { url_.setUserName(_userName); }

    inline void SetPassword(const QString &_password)
    { url_.setPassword(_password); }

    inline void SetScheme(const QString & _scheme)
    { url_.setScheme(_scheme); }

signals:

    void SignalSendProgress(qint64 _bytesSent, qint64 _bytesTotal);

    void SignalReceiveProgress(qint64 _bytesReceived, qint64 _bytesTotal);

    void SignalUploadFinished();

    void SignalReceiveFinished();

public slots:

    void SlotError(QNetworkReply::NetworkError error);

    void SlotRead();

private:
    QUrl url_;
    QString path_;
    QNetworkAccessManager manager_;
};

#endif //AUTOUPDATE_FTPMANAGER_H
